<?php
declare (strict_types = 1);

namespace app\common\middleware;

use think\Exception;

class MethodCheck
{
    /**
     * 处理请求
     * @param $request
     * @param \Closure $next
     * @param $method
     * @return mixed
     */
    public function handle($request, \Closure $next, $method)
    {
        $method = strtolower($method);

        if (request()->isAjax())

            $curMethod = 'ajax';
        else{
            $curMethod = strtolower(request()->method());
        }
        if($method !== $curMethod) abort(405, '请求方式不被允许.');

        return $next($request);

    }
}
